package com.uls.web.controller.lh;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.uls.lh.domain.LhCarinfo;
import com.uls.lh.mapper.LhCarinfoMapper;
import com.uls.lh.service.ILhCarinfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.lh.domain.LhCarFee;
import com.uls.lh.service.ILhCarFeeService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 车辆费用管理（按天数计算）Controller
 * 
 * @author lh
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/lh/fee")
public class LhCarFeeController extends BaseController
{
    @Autowired
    private ILhCarFeeService lhCarFeeService;
    @Autowired
    private ILhCarinfoService lhCarinfoService;

    /**
     * 查询车辆费用管理（按天数计算）列表
     */
    @PreAuthorize("@ss.hasPermi('lh:fee:list')")
    @GetMapping("/list")
    public TableDataInfo list(LhCarFee lhCarFee)
    {
        startPage();
        List<LhCarFee> list = lhCarFeeService.selectLhCarFeeList(lhCarFee);
        for (LhCarFee lhCarFee1:list){
            Long CarId=lhCarFee1.getCarId();
            LhCarinfo lhCarinfo= lhCarinfoService.selectLhCarinfoByCarId(CarId);
            if (lhCarinfo != null){
                lhCarFee1.setModel(lhCarinfo.getModel());
            }
        }
        System.out.println(list);

        return getDataTable(list);
    }

    /**
     * 导出车辆费用管理（按天数计算）列表
     */
    @PreAuthorize("@ss.hasPermi('lh:fee:export')")
    @Log(title = "车辆费用管理（按天数计算）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LhCarFee lhCarFee)
    {
        List<LhCarFee> list = lhCarFeeService.selectLhCarFeeList(lhCarFee);
        ExcelUtil<LhCarFee> util = new ExcelUtil<LhCarFee>(LhCarFee.class);
        util.exportExcel(response, list, "车辆费用管理（按天数计算）数据");
    }

    /**
     * 获取车辆费用管理（按天数计算）详细信息
     */
    @PreAuthorize("@ss.hasPermi('lh:fee:query')")
    @GetMapping(value = "/{feeId}")
    public AjaxResult getInfo(@PathVariable("feeId") Long feeId)
    {
        return success(lhCarFeeService.selectLhCarFeeByFeeId(feeId));
    }

    /**
     * 新增车辆费用管理（按天数计算）
     */
    @PreAuthorize("@ss.hasPermi('lh:fee:add')")
    @Log(title = "车辆费用管理（按天数计算）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LhCarFee lhCarFee)
    {
        return toAjax(lhCarFeeService.insertLhCarFee(lhCarFee));
    }

    /**
     * 修改车辆费用管理（按天数计算）
     */
    @PreAuthorize("@ss.hasPermi('lh:fee:edit')")
    @Log(title = "车辆费用管理（按天数计算）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LhCarFee lhCarFee)
    {
        return toAjax(lhCarFeeService.updateLhCarFee(lhCarFee));
    }

    /**
     * 删除车辆费用管理（按天数计算）
     */
    @PreAuthorize("@ss.hasPermi('lh:fee:remove')")
    @Log(title = "车辆费用管理（按天数计算）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{feeIds}")
    public AjaxResult remove(@PathVariable Long[] feeIds)
    {
        return toAjax(lhCarFeeService.deleteLhCarFeeByFeeIds(feeIds));
    }
}
